--[[
/**
 * 援护
 * [0]	时间间隔
 * [1] 无敌buffId
 * [2] 护盾buffId
 * [3] buff层数
 */
]]
---@class BuffEffect13100 : BaseBuffEffect
BuffEffect13100 = ClientFight.CreateClass("BuffEffect13100", ClientFight.BaseBuffEffect)
local t = BuffEffect13100
t.BUFF_EFFECT_PARAMETERS = "EFFECT_PARAMETERS_BUFF_";
---@param fight Fight
---@param buff FighterBuff
function t:action(fight, buff, ...)
    local parameters =  {...}
            -- 援护者
    local fighter = buff.source;
    -- 被援护者
    local target = buff.target;

    if (FighterStateEnum.is(target, FighterStateEnum.LOCK_HP)) then
    return IBuffEffect.FAIL;
    end

    local result = parameters[3];

    local frame = fight.frame;
    -- 援护者是否已经死亡
    if (fighter:isDie()) then
    return IBuffEffect.REMOVE;
    end
    -- 援护者和被援护者是否为同一人
    if (fighter.fighterId == target.fighterId) then
    return IBuffEffect.REMOVE;
    end

    -- 上一次触发时间是否在间隔以内
    local preFrameStr = fighter.paramemters[t.BUFF_EFFECT_PARAMETERS .. buff.modelId];
    if (not string.IsEmpty(preFrameStr)) then
    local preFrame = tonumber(preFrameStr);
    if (frame - preFrame < buff.buffBean.f_BuffEffectValue[1] / Global.FIGHT_FRAME) then
    return IBuffEffect.FAIL;
    end
    end
    fighter.paramemters[t.BUFF_EFFECT_PARAMETERS .. buff.modelId] =  tostring(frame);
    -- 把血加回来
    DamageManager.setFighterHp(fight, target, fighter, nil, 0, 1,
    target.hp + 1, false, false, false);
    -- 触发技能
    --triggerSkill(fight, fighter, target, buff.buffBean.f_BuffEffectValue[1]);
    BuffManager.addBuff(fight, buff.skill, fighter, target, false, buff.buffBean.f_BuffEffectValue[2], buff.buffBean.f_BuffEffectValue[4]);
    BuffManager.addBuff(fight, buff.skill, fighter, target, false, buff.buffBean.f_BuffEffectValue[3], buff.buffBean.f_BuffEffectValue[4]);

    SkillRoleMgr.savePathFile( "[" .. fight.frame .. "][EFFECT]Fighter " .. buff.target.fighterId .. " Buff"
    .. buff.modelId .. " 触发援护  援护者pos:" ..  getJsonStr(fighter.position) .. "  被援护者pos:"
    .. getJsonStr(target.position) .. "被援护者hp:" .. target.hp
    );
    return ClientFight.BaseBuffEffect.action(self,fight, buff, ...);
end

t.New()